package com.banciyuan.bcywebview.base.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.banciyuan.bcywebview.R;

/**
 * Created by squall on 2015/10/10.
 */
public class UpdateDialog extends Dialog {
    public UpdateDialog(Context context) {
        super(context);
    }

    public UpdateDialog(Context context, int theme) {
        super(context, theme);
    }

    protected UpdateDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    private String log = "";
    private TextView log_tv;
    private Button update_button;
    private Button updateLater_button;
    private View.OnClickListener onUpdateClickListener;
    private View.OnClickListener onLaterUpdateClickListener;
    private boolean showUpdateLaterBtn;

    public View.OnClickListener getOnUpdateClickListener() {
        return onUpdateClickListener;
    }

    public void setOnUpdateClickListener(View.OnClickListener onUpdateClickListener) {
        this.onUpdateClickListener = onUpdateClickListener;
    }

    public void setOnLaterUpdateClickListener(View.OnClickListener onLaterUpdateClickListener) {
        this.onLaterUpdateClickListener = onLaterUpdateClickListener;
    }

    public String getLog() {
        return log;
    }

    public void setLog(String log) {
        this.log = log;
    }

    public void showUpdateLaterBtn(boolean showUpdateLaterBtn) {
        this.showUpdateLaterBtn = showUpdateLaterBtn;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.update_dialog);
        log_tv = (TextView) findViewById(R.id.update_log);
        update_button = (Button) findViewById(R.id.update_btn);
        updateLater_button = (Button) findViewById(R.id.update_later_btn);
        updateLater_button.setVisibility(showUpdateLaterBtn ? View.VISIBLE : View.GONE);
        log_tv.setMovementMethod(ScrollingMovementMethod.getInstance());
        log_tv.setText(log);
        update_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onUpdateClickListener.onClick(view);
                dismiss();
            }
        });
        updateLater_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != onLaterUpdateClickListener)
                    onLaterUpdateClickListener.onClick(v);
                dismiss();
            }
        });
    }
}